package com.white.server.impl;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class ClientHeart implements Runnable {

    private final Socket serverSocket;
    private ObjectOutputStream outputStream;
    public ClientHeart(Socket serverSocket, ObjectOutputStream outputStream) {
        this.serverSocket = serverSocket;
        this.outputStream = outputStream;
    }

    @Override
    public void run() {
        System.out.println("心跳线程运行中...");
        try {
            while (true) {
                Thread.sleep(5000);
                outputStream.writeObject("心跳包");
                outputStream.flush();
            }
        } catch (IOException | InterruptedException e) {
            Client.reConnection();
            e.printStackTrace();
        }
    }
}
